﻿GY.Bill.OfferDetail = {
    CheckInput: function () {
        var msg = "";

        if ($("#txtMonthInterest").val().trim() == "") {
            msg = "请输入月息";
            return msg;
        }

        if ($("#div_BillMethod").find(".active").attr("data-val") == undefined) {
            msg = "请选择操作方式";
            return msg;
        }

        if ($("#txtOfferLocation").val().trim() == "") {
            msg = "请输入操作地点";
            return msg;
        }

        /*if ($("#txtRemark").val().trim() == "") {
            msg = "请输入操作要求";
            return msg;
        }*/

        return msg;
    },
    GetOfferModel: function () {
        var $divMain = $("#divMain");
        var model = {
            InviteId: $divMain.attr("data-inviteid"),
            MonthInterest: $("#txtMonthInterest").val(),
            BillType: $divMain.attr("data-type"),
            BillId: $divMain.attr("data-billid"),
            OfferType: $divMain.attr("data-offertype"),
            OfferAmount: 0,
            OfferId: $divMain.attr("data-offerid"),
            Remark: $("#txtRemark").val(),
            OfferMethod: $("#div_BillMethod").find(".active").attr("data-val"),
            OfferLocation: $("#txtOfferLocation").val()
        };

        return model;
    },
    SaveOffer: function () {
        $.ajax({
            type: "Post",
            url: $("#divMain").attr("data-url"),
            data: GY.Bill.OfferDetail.GetOfferModel(),
            dataType: "json",
            success: function (result) {
                if (result.code == 1) {
                    $(".shade").hide();
                    $(".mask_int").hide();

                    $("#btn_offer_show").text("修改报价");
                    GY.Bill.Common.ShowSuccessTip();

                    GY.Bill.OfferDetail.RefreshOffer();
                    //window.location.reload();
                }
            }
        });
    },
    RefreshOffer: function () {
        var $myoffer = $("#div_myoffer");
        $.ajax({
            type: "Post",
            url: $myoffer.attr("data-url"),
            data: { billId: $("#divMain").attr("data-billid"), type: $("#divMain").attr("data-type") },
            dataType: "html",
            async: false,
            success: function (result) {
                if (result.trim() != "") {
                    //显示信息
                    $myoffer.show();
                    $myoffer.html(result);
                }
            }
        });
    }
};
(function () {
    $(function () {
        if (showTime.trim() == "") {
            var times = new GY.Bill.Common.CountDown(addTime, ".countdown .time");
        }

        //弹窗
        $(".mask").on("tap", ".short", function () {
            $(".shade").hide();
            $(".mask").hide();
        });

        $(".shade").on("tap", function () {
            $(".shade").hide();
            $(".mask").hide();
        });
        
        $("#btn_offer_show").on("tap", function () {
            fnShade($(".shade"));
            $(".shade").show();
            $(".mask_int").show();
        });
        $(".mask_int").on("focus", "input", function () {
            $(".mask_int").css("position", "relative");
            fnShade($(".shade"));
        });
        $(".mask_int").on("blur", "input", function () {
            $(".mask_int").css("position", "fixed");
            fnShade($(".shade"));
        });

        $("#btn_offer").on("tap", function () {
            var msg = GY.Bill.OfferDetail.CheckInput();
            if (msg != "") {
                //显示错误消息
                ShowTip(msg);
                return;
            } else {
                var flag = GY.Bill.Common.SaveCheck($(this));

                if (flag) {
                    GY.Bill.OfferDetail.SaveOffer();
                }
            }
        });

        //修改用户信息并保存报价信息
        $("#btnSaveUserOffer").on("tap", function () {
            var flag = GY.Bill.Common.SaveUser();

            if (flag) {
                $("#btn_offer").attr("data-check", 1);
                GY.Bill.OfferDetail.SaveOffer();
            }
        });

        //操作方式选择
        $("#div_BillMethod").on("tap", "label", function () {
            $(this).parent().find("i").removeClass("active");
            $(this).children("i").addClass("active");
        });
    });
})();

